package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.ProYear;
import com.ruoyi.system.service.ProjectsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IYearMessageService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 年度信息Controller
 * 
 * @author ruoyi
 * @date 2021-01-07
 */
@RestController
@RequestMapping("/system/message/year")
public class YearMessageController extends BaseController
{
    @Autowired
    private IYearMessageService yearMessageService;
    @Autowired
    private ProjectsService projectsService;

    //年度信息回显
    //@PreAuthorize("@ss.hasPermi('system:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProYear year)
    {
        startPage();
        List<ProYear> proYear = projectsService.getProYear(year.getProId());
        return getDataTable(proYear);
    }

    //修改年度信息
    //@PreAuthorize("@ss.hasPermi('system:message:edit')")
    @Log(title = "修改年度信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody  ProYear proYear)
    {
        if(yearMessageService.updateYearMessage(proYear)==1){
            return AjaxResult.success("修改成功");
        }else {
            return AjaxResult.error(proYear.getMesYear()+"年的年度信息已录入无法修改");
        }
    }


    //删除年度信息
    //@PreAuthorize("@ss.hasPermi('system:message:remove')")
    @Log(title = "删除年度信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mesId}")
    public AjaxResult remove(@PathVariable Long mesId)
    {
        return toAjax(yearMessageService.deleteYearMessageById(mesId));
    }


    //新增年度信息
    //@PreAuthorize("@ss.hasPermi('system:message:add')")
    @Log(title = "新增年度信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProYear proYear)
    {
        if(yearMessageService.insertYearMessage(proYear)==1){
            return AjaxResult.success("新增成功");
        }else {
            return AjaxResult.error(proYear.getMesYear()+"年的年度信息已录入无法重复录入");
        }
    }



//    /**
//     * 导出年度信息列表
//     */
////    @PreAuthorize("@ss.hasPermi('system:message:export')")
//    @Log(title = "年度信息", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(YearMessage yearMessage)
//    {
//        List<YearMessage> list = yearMessageService.selectYearMessageList(yearMessage);
//        ExcelUtil<YearMessage> util = new ExcelUtil<YearMessage>(YearMessage.class);
//        return util.exportExcel(list, "message");
//    }





}
